home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue43 / delay / D2Support.pas next >
Encoding:
Pascal/Delphi Source File  |  1999-01-27  |  908 b   |  54 lines

  1. unit D2Support;
  2.  
  3. interface
  4.  
  5. {$IFDEF VER90}
  6.  
  7. uses
  8.   Windows,
  9.   SysUtils;
  10.  
  11. type
  12.   EWin32Error = class(Exception)
  13.   public
  14.     ErrorCode: DWORD;
  15.   end;
  16.  
  17. procedure RaiseLastWin32Error;
  18.  
  19. function Win32Check(RetVal: BOOL): BOOL;
  20.  
  21. {$ENDIF}
  22.  
  23. implementation
  24.  
  25. {$IFDEF VER90}
  26. const
  27.   SWin32Error = 'Win32 Error.  Code: %d.'#10'%s';
  28.   SUnkWin32Error = 'A Win32 API function failed';
  29.  
  30. procedure RaiseLastWin32Error;
  31. var
  32.   LastError: DWORD;
  33.   Error: EWin32Error;
  34. begin
  35.   LastError := GetLastError;
  36.   if LastError <> ERROR_SUCCESS then
  37.     Error := EWin32Error.CreateFmt(SWin32Error, [LastError,
  38.       SysErrorMessage(LastError)])
  39.   else
  40.     Error := EWin32Error.Create(SUnkWin32Error);
  41.   Error.ErrorCode := LastError;
  42.   raise Error;
  43. end;
  44.  
  45. function Win32Check(RetVal: BOOL): BOOL;
  46. begin
  47.   if not RetVal then RaiseLastWin32Error;
  48.   Result := RetVal;
  49. end;
  50.  
  51. {$ENDIF}
  52.  
  53. end.
  54.